package base.reflect;

/**
 * @Author Fizz Pu
 * @Date 2021/4/1 下午10:15
 * @Version 1.0
 * 失之毫厘，缪之千里！
 */
import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class AllMethod implements Serializable {
    private static final long serialVersionUID = -2862585049955236662L;


    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("base.reflect.AllMethod");
        Method method[] = clazz.getMethods(); // 所有的public方法
        for (int i = 0; i < method.length; ++i) {
            Class<?> returnType = method[i].getReturnType();
            Class<?> para[] = method[i].getParameterTypes();
            int temp = method[i].getModifiers();
            System.out.print(Modifier.toString(temp) + " "); // 修饰符
            System.out.print(returnType.getName() + "  ");  // 返回类型
            System.out.print(method[i].getName() + " ");   // 方法名
            System.out.print("(");

            // 参数列表
            for (int j = 0; j < para.length; ++j) {
                System.out.print(para[j].getName() + " " + "arg" + j);
                if (j < para.length - 1) {
                    System.out.print(",");
                }
            }

            // 异常
            Class<?> exce[] = method[i].getExceptionTypes();
            if (exce.length > 0) {
                System.out.print(") throws ");
                for (int k = 0; k < exce.length; ++k) {
                    System.out.print(exce[k].getName() + " ");
                    if (k < exce.length - 1) {
                        System.out.print(",");
                    }
                }
            } else {
                System.out.print(")");
            }
            System.out.println();
        }
    }
}
